/**
 * 功能描述 总表格触发事件
 */
define(function (require, exports, module) {
	var store = require("store");
	var activeUser = store.get("user");
	var Dialog=require("dialog");
	var aw = require("ajaxwrapper");
	var Form = require("form");
	
    module.exports = {
    	UpDateMeter : function(data, widget){

    		var remarkForm =new Form({
				parentNode:".J-form-dialog",
				autoRender : false,
        		model:{
        			layout:"2_1",
					id:"remarkForm",
					defaultButton:false,
					items:[{
						name:"cardNo",
						label:"消费券编号",
						readonly: true
					},{
						name:"name",
						label:"会员",
						readonly: true
					},{
						name:"product",
						label:"产品",
						readonly: true
					},{
						name:"productType",
						label:"产品类型",
						readonly: true
					},{
						name:"memberCertificates",
						label:"会员证号",
						readonly: true
					},{
						name:"price",
						label:"返券金额(元)",
					},{
						name:"operator",
						label:"经办人",
						readonly: true
					},{
						name:"operateDate",
						label:"返券日期",
						readonly: true
					},{
						name:"remarkDetail",
						label:"备注",
						"break":true,
						defaultValue : moment(new Date()).format("YYYY年MM月DD日")+"返券"
					}]
				 }
			});
			widget.set("remarkForm",remarkForm);
			
			//根据返券规则查询返券金额
			aw.ajax({
				url:"api/welfareconsumptioncoupon/queryrule",
				data:{
					pkWelfarecc:data.welfareConsumptionCoupon.pkWelfarecc,
					fetchProperties:"*" 
				},
				dataType:"json",
				success:function(dataold){
					Dialog.showComponent(remarkForm,{
						defaultButton:false,
						title: "返券",
						buttons :[{
							id:"save",
							text:"确定",
							className:"btn-primary",
							handler:function(){
								if(remarkForm.valid()){
									var FormData = remarkForm.getData();
									var saveData = {};
									saveData.pkWelfarecc = data.welfareConsumptionCoupon.pkWelfarecc;
									saveData.price=FormData.price;
									saveData.remarkDetail = FormData.remarkDetail;
									saveData.operator = FormData.FormData;
									saveData.operateDate = moment().format("YYYY.MM.DD");
									aw.saveOrUpdate("api/welfareconsumptioncoupon/saveall",aw.customParam(saveData),function(saveData){
										Dialog.close();
					          			widget.get("grid").refresh();
					       			});
								};
							}
						},{
							id:"close",
							text:"取消",
							handler:function(){
								Dialog.close();
							}
						}]
					});
					
					var form = widget.get("remarkForm");
					form.setValue("cardNo",data.welfareConsumptionCoupon.cardNo);
					form.setValue("name",data.welfareConsumptionCoupon.travelContract.member.personalInfo.name);
					form.setValue("product",data.welfareConsumptionCoupon.travelContract.productType.product.name);
					form.setValue("productType",data.welfareConsumptionCoupon.travelContract.productType.name);
					form.setValue("memberCertificates",data.welfareConsumptionCoupon.travelContract.memberCertificates);
					form.setValue("operator",activeUser.name);
					form.setValue("operateDate",moment().format("YYYY.MM.DD"));
					form.setValue("price",dataold);
					
				}
			});
    	},
    };
});
